<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ include file="../include/taglib.jsp"%>
<%@ page import = "java.util.*" %>
<%@ page import = "com.sinodata.bsm.common.vo.Probe" %>
<%@ page import = "com.sinodata.bsm.common.constants.RelationConstants" %>

<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>资源新增</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>    
    <%@ include file="../include/common.jsp"%>
    <%@ include file="../include/form.jsp"%>
    <%@ include file="../include/tree.jsp"%>
     <%@ include file="../include/jbox.jsp"%>
    <%@ include file="../include/table.jsp"%>
   	<link rel="stylesheet" media="all" type="text/css" href="${pageContext.request.contextPath}/style/default/tree/zTreeStyle.css" />
   	<style type="text/css">
		.ztree {margin-top: 5px;border: 1px solid #617775;background: #fff;width:220px;height:350px;overflow-y:scroll;overflow-x:auto;}
	</style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/tree/jquery.ztree.all-3.1.min.js"></script>
    <script type="text/javascript" src="log4javascript.js"></script>
    
     <link rel="stylesheet" type="text/css"
	      href="${pageContext.request.contextPath}/style/default/select/jquery.image.select.css" />
	 <script type="text/javascript"
	      src="${pageContext.request.contextPath}/js/select/jquery.image.select.min.js"></script>
	
	<script type=text/javascript>
	var eventTypeTableRowId = 0;
	var eventTypeData = new Array();
	var propertyTableRowId = 0;
	var propertyData = new Array();
	function addEventType(){
		var url ="iframe:resource/res!inputEventtype.action";
		var opt = { title: "新增事件类别",width:520,height:150,buttons: {}};
		getTopWin(window).openjBox(url,opt,'add-res-eventtype',window);
	}
	function addProperty(){
		var url ="iframe:resource/res!inputProperty.action";
		var opt = { title: "新增指标",width:520,height:150,buttons: {}};
		getTopWin(window).openjBox(url,opt,'add-res-property',window);
	}
	function findObj(theObj, theDoc)
    {
          var p, i, foundObj;
         
          if(!theDoc) theDoc = document;
          if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
          {
            theDoc = parent.frames[theObj.substring(p+1)].document;
            theObj = theObj.substring(0,p);
          }
          if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
          for (i=0; !foundObj && i < theDoc.forms.length; i++)
            foundObj = theDoc.forms[theObj];
          for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
            foundObj = findObj(theObj,theDoc.layers.document);
          if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
         
          return foundObj;
    }
	function addEventTypeRow(name,recoverableName,recoverable){
			var tbl = findObj("eventTypeTable",document);             
		   	var newTR = tbl.insertRow(tbl.rows.length);
		    var newNameTD=newTR.insertCell(0);
		   	newNameTD.innerHTML ="<a href='javascript:Goto();' onclick='deleteEventTypeRow(this,"+eventTypeTableRowId+")'>删除</a>";         
		   	var newNameTD=newTR.insertCell(1);
		  	newNameTD.innerHTML =name;
		   	var newNameTD=newTR.insertCell(2);
		   	newNameTD.innerHTML =recoverableName;
		  	var str =name+"|"+recoverable;
		  	eventTypeData[eventTypeTableRowId++] = str;
		  	//改变奇偶颜色
		  	$('#eventTypeTable thead tr:even').addClass('even');
			$('#eventTypeTable thead tr:odd').addClass('odd');
	}
	function addPropertyRow(name,dataTypeName,dataTypeId){
		var tbl = findObj("propertyTable",document);             
	   	var newTR = tbl.insertRow(tbl.rows.length);
	    var newNameTD=newTR.insertCell(0);
	   	newNameTD.innerHTML ="<a href='javascript:Goto();' onclick='deletePropertyRow(this,"+propertyTableRowId+")'>删除</a>";         
	   	var newNameTD=newTR.insertCell(1);
	  	newNameTD.innerHTML =name;
	   	var newNameTD=newTR.insertCell(2);
	   	newNameTD.innerHTML =dataTypeName;
	  	var str =name+"|"+dataTypeId;
	  	propertyData[propertyTableRowId++] = str;
	  	//改变奇偶颜色
	  	$('#propertyTable thead tr:even').addClass('even');
		$('#propertyTable thead tr:odd').addClass('odd');
	}
	function Goto() {
		
	}
	function deleteEventTypeRow(obj,rowId){ 
		var tr = obj.parentNode.parentNode;
		var tbody = tr.parentNode;
		tbody.removeChild(tr);
		eventTypeData[rowId] = "";
		//改变奇偶颜色
		$('#eventTypeTable thead tr').removeClass('even');
		$('#eventTypeTable thead tr').removeClass('odd');
		$('#eventTypeTable thead tr:even').addClass('even');
		$('#eventTypeTable thead tr:odd').addClass('odd');
	} 
	function deletePropertyRow(obj,rowId){ 
		var tr = obj.parentNode.parentNode;
		var tbody = tr.parentNode;
		tbody.removeChild(tr);
		propertyData[rowId] = "";
		//改变奇偶颜色
		$('#propertyTable thead tr').removeClass('even');
		$('#propertyTable thead tr').removeClass('odd');
		$('#propertyTable thead tr:even').addClass('even');
		$('#propertyTable thead tr:odd').addClass('odd');
	} 
		function showMenu() { 
			var cityObj = $("#resTypeName");
			var cityOffset = $("#resTypeName").offset();
			$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			
			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "resTypeId" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("resTypeTree"),
			nodes = zTree.getSelectedNodes(),
			v = "";
			if(nodes.length!=1 ){
				return;
			}
			if( nodes[0].isParent){
				zTree.expandNode(nodes[0]);
				return;
			}
			var resTypeId = nodes[0].id;
			selfFound = nodes[0].selfFound;
			if(selfFound!=1){
				addAttribute(resTypeId);
			}else{
				$(".tmptr").each(function(){
  					$(this).remove();
				});
			}
			hideMenu();
			
			$("#resTypeId").attr("value", resTypeId);
			$("#resTypeName").attr("value", nodes[0].name);
			$("#resTypeName").blur();
			
		}
		function showRelTree() {
			var cityObj = $("#resRelName");
			var cityOffset = $("#resRelName").offset();
			var rTree = $.fn.zTree.getZTreeObj("relRelTree");
			var nodes = rTree.getSelectedNodes();
			if(nodes.length==0){
				var defaultNode = rTree.getNodeByParam("id", 102, null);
				rTree.selectNode(defaultNode);
			}
			$("#relContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			$("body").bind("mousedown", onRelTreeDown);
		}
		function resetRelTree()
		{	var rTree = $.fn.zTree.getZTreeObj("relRelTree");
			var defaultNode = rTree.getNodeByParam("id", 102, null);
			rTree.selectNode(defaultNode);
			$("#resRelId").attr("value", defaultNode.id);
			$("#resRelName").attr("value",defaultNode.name);
		}
		function onRelTreeDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "resRelId" || event.target.id == "relContent" || $(event.target).parents("#relContent").length>0)) {
				$("#relContent").fadeOut("fast");
				$("body").unbind("mousedown", onRelTreeDown);
			}
		}
		function relNodeClick(e, treeId, treeNode) {
			$("#relContent").fadeOut("fast");
			$("body").unbind("mousedown", onRelTreeDown);
			$("#resRelId").attr("value", treeNode.id);
			$("#resRelName").attr("value",treeNode.name);
			$("#resRelName").blur();
		}
		
		/**
		* update fan
		* resTypeId:资源类别唯一ID
		* typeValue:资源类型ID 例：主机、数据库、中间件 在资源向导页面里面有标识
		*/
		function addAttribute(resTypeId,typeValue){
			/*$.ajax({
	      		url:'res-type!findAttribute.action?id='+resTypeId+'&t='+new Date().getMilliseconds(),
	      		global:false,
	      		async: false,
	      		dataType: "json",
	      		success : function(items){
	      			var tr = $("#codeTr") ; //.insertAfter("#foo");
	      			var tb = $("#restable");
	      			$(".tmptr").each(function(){
	  					$(this).remove();
					});
	      			for(var i=0; i<items.length; i++){
	      				var id= items[i].id;
	      				var name= items[i].name;
	      				var dataUnit = items[i].dataUnit;
	      				
	      				if(dataUnit!=null&&dataUnit!=''){
	      					name +="("+dataUnit+")";
	      				}
	      				
	      				var redHint = "";
	      				
	      				if(typeValue!=null&&typeValue==3||typeValue==4){
	      					redHint = "<span class='span_alert'>*</span>";
	      				}
	      				var str='<tr class="tmptr"><td class="td_left"   >'+redHint+name+'</td><td class="td_right">';
	      				str+='<input type="text" name="prop_'+id+'" id="prop_'+id+'"  maxlength="150"  class="input_text"/>';
	      				str+='</tr>';
	      				var tmpTr = $(str);
	      				tmpTr.insertBefore($('#desc').prev());
	      			}
	      		}
      	  });*/
		}
		function addStyle(desc){
			id(desc == $('$'))
		}
		var resRelTreeConfig = {
			async: {
				enable: true,
				url:"res-relation!typeTree.action",
				dataType: "text",
				autoParam:["id"]
			},
			callback: {
				onClick: relNodeClick
			},
			view: {
				dblClickExpand: false,
				showLine: false
			}
		};
		var setting = {
			async: {
				enable: true,
				url:"res-type!typeTree.action?isDisplayFind=false",
				dataType: "text",
				autoParam:["id"]
			},
			callback: {
				onClick: onClick
			},
			view: {
				dblClickExpand: false,
				showLine: false
			}
		};
		
		
		//resId:资源ID  
		function refreshViewTree(resId)
		{		
			var tree = window.parent.parent.getResTree();
			var nodes = tree.getSelectedNodes();
			if($("#isRoot:checked").length==1){
				 window.parent.parent.refreshTree();
			}else if (nodes.length>0) {
				if(!nodes[0].isParent){
					nodes[0].isParent =true;
					tree.updateNode(nodes[0]);
				}
				tree.reAsyncChildNodes(nodes[0], "refresh");
			}else{
				 window.parent.parent.refreshTree();
			}
			
		}
		
		    //默认采集协议
			var agreementId = '${agreement}';
			var agreements =[
				{'text':'主机配置','url':'config/host-config!add.action','updateUrl':'config/host-config!input.action','title':'主机配置','windowId':'add-host-config'},
				{'text':'WMI配置','url':'config/wmi-config!add.action','updateUrl':'config/wmi-config!input.action','title':'WMI配置','windowId':'add-wmi-config'},
				{'text':'数据库配置','url':'config/db-config!add.action','updateUrl':'config/db-config!input.action','title':'数据库配置','windowId':'add-db-config'},
				{'text':'JMX配置','url':'config/jmx-config!add.action','updateUrl':'config/jmx-config!input.action','title':'JMX配置','windowId':'add-jmx-config'},
				{'text':'数据库配置','url':'config/db-config!add.action','updateUrl':'config/db-config!input.action','title':'数据库配置','windowId':'add-db2-config'}
			];
			
		$(document).ready(function(){
			          var log = log4javascript.getLogger();
			          log.info('a');

						if(${resType.id} == '1205040500000'){
							$("#DBTypeTr").css({"display":""});
							$("#DBNameTr").css({"display":""});
							$("#SQLTr").css({"display":""});
						}else if(${resType.id} == '1205040600000'){
							$("#regexTr").css({"display":""});
							$("#shellTr").css({"display":""});
						}
						$.formValidator.initConfig({
										formid:"resForm",
										onerror:function(msg){},
										onsuccess:function(){
											var presname = $('#presname').text();
											if((presname==null||presname=='')&&$('#isRoot').is(':checked')==false){
												getTopWin(window).getMessageBox().alert("在没有选择父资源的情况下，请设置为顶级节点。","提示");
												return false;
											}
											try{
											 $.ajax({
													type:'post',
													url:'res!save.action?flag=other',
													data:$('#resForm').serialize()+"&propertyData="+propertyData+"&eventTypeData="+eventTypeData,
													global:false,
													async:false,
													cache:false,
													dataType:'json',
													success:function(data,textStatus){
														var isFind = data.isFind;
														refreshViewTree();
														if(isFind=='true'){ //可发现
														  window.parent.location.assign('res-find!view.action?id='+data.resId+'');
														}else{
															getTopWin(window).getMessageBox().tip('保存资源成功。', 'success',{timeout: 1500});
															$('#resForm').trigger("reset");
															resetIt();
														}
													},
													
													error:function(){
														
														$.jBox.alert('服务器内部错误,请联系管理员','错误');
													}
				 		   					   });
											}catch(e){
												log.info(e);
											}
										     return false;
										}});
				$("#resTypeName").formValidator({onshow:"请选择资源类型",onfocus:"请选择资源类型"})
			          .inputValidator({min:1, onerror:"请一选择资源类型"});
			   	$("#ip").formValidator({onshow:"请输入资源IP",oncorrect:"输入正确"}).inputValidator({min:1, onerror:"请输入正确IP"}).functionValidator({
	    		fun:function(val,elem){
	    			var v = $("#ip").val();
	        		if (!isIP(v)) {
						return "请输入正确IP"
					}
					return true;
				}
			});
			$("#name").formValidator({onshow:"请输入资源名称",onfocus:"资源名称最大长度为40"})
			          .inputValidator({min:1,onerror:"资源名称不能为空"})
			          .functionValidator({
			          	  fun:function(val,elem){
			          	     if(val.length>40){
			          	     	return "资源名称长度输入有误";
			          	     }
			          	     return true;
			          	  }
			          });
			$("#probeId").formValidator({onshow:"请选择采集器",onfocus:"采集器为必选项"})
					   .inputValidator({min:1,onerror: "采集器为必选项"})
					   .functionValidator({
					   		fun:function(val,elem){
					   			return true;
					   		}
					   });
				
		    $.fn.zTree.init($("#resTypeTree"),setting);
			$.fn.zTree.init($("#relRelTree"),resRelTreeConfig);
						
			//默认资源类型
			var resTypeId = '${resType.id}';
			var isResFind = '${isResFindDef}';
			if(resTypeId!=''){
				$('#resTypeId').val('${resType.id}');
				$('#resTypeName').val('${resType.name}');
				$('#resTypeName').attr('disabled','disabled');
				if(isResFind=='false'){ //没有发现程序
					addAttribute(resTypeId,agreementId);
				}
				if(agreementId!=''){
					$('#agreementTr').show();
				}else{
					$('#agreementTr').hide();
				}
				
			}else{
				$('#resTypeName').removeAttr('disabled');
				$('#agreementTr').hide();
			}
			
			if(agreementId==1||agreementId==2){
				$('#ip').live('blur',function(){
					isConfigireAgreement(this.id,agreementId==1?'HOST':'WMI');
				});
			}else if(agreementId==3||agreementId==4){ 
				//其它参数 例：数据库的实例名,JMX的端口号
				var paramOb = $($('#resRelTr').next().children('td')[1]).children('input')[0];
				
				/*
				* 如果当前视图下没有资源的情况
				*   父资源为null
				*/
				var havingParent ='${res.name==null}';
				//没有父资源
				if(havingParent=='true'){
					paramOb = $($('#agreementTr').prev().children('td')[1]).children('input')[0];
				}
				
				if(agreementId==3){
					$('#'+$(paramOb).attr('id')+',#ip').live('blur',function(){
						isConfigireAgreement(this.id,'JDBC');
					});
				}else{
					$('#ip,#'+$(paramOb).attr('id')+'').live('blur',function(){ //websharee
						isConfigireAgreement(this.id,'JMX');
					});
				}
			}else if(agreementId==5){ //sql记录查询
				//var dbName =$($('#resRelTr').next().next().children('td')[1]).children('input')[0]; //数据库名  paramOb为数据库类型
				var dbName = '#DBName'; 
				$('#'+$(paramOb).attr('id')+',#ip,#'+$(dbName).attr('id')+',#DBType').live('blur',function(){
						isConfigireAgreement(this.id,'JDBC');
				});
			}
			
			//显示probe状态
			$("#probeId").msDropDown().data("dd");
		});
		
		//判断当前资源类型是否配置采集协议
		function isConfigireAgreement(id,typeValue){
			var ip = $('#ip').val();
			$.ajax({
				type:'post',
				url:'../config/config!protocolParameters.action',
				data:{'type':typeValue},
				global:false,
				async:false,
				cache:false,
				dataType:'json',
				success:function(data,textStatus){
					var msg = "<label style='margin-left:10px;color:red;'>当前资源未配置监控协议</label>";
					var paramers = data;
					var paramerter ;
					var resTypeName = '${resType.name}';
					$.each(paramers,function(index,ob){
						if(ob.type==typeValue&&ob.ip==ip){
							 var compareValue ='';
							if(agreementId==3){
							 		if(id=='ip'){
								 		var databaseOb = $($('#resRelTr').next().children('td')[1]).children('input')[0];
								 		compareValue = $(databaseOb).val();
								 	}else{
								 		compareValue = $('#'+id+'').val();
								 	}
								 	if(ob.instName==compareValue&&ob.instType==resTypeName.toLocaleLowerCase()){
								 			paramerter = ob;
											msg = "<label style='margin-left:10px;color:green;'>当前资源已经配置了监控协议</label>";
											return false;
								 	}
							}else if(agreementId==1||agreementId==2){
								paramerter = ob;
								msg = "<label style='margin-left:10px;color:green;'>当前资源已经配置了监控协议</label>";
								return false;
							}else if(agreementId==4){
									if(id=='ip'){
										if(resTypeName=='IIS'||resTypeName=='apache'){ //特殊情况
											compareValue = $('#'+id+'').val();
										}else{
											var port = $($('#resRelTr').next().children('td')[1]).children('input')[0];
								 			compareValue = $(port).val();
										}
								 	}else{
								 		compareValue = $('#'+id+'').val();
								 	}
									if(ob.port==compareValue&&ob.instType==resTypeName.toLocaleLowerCase()){
										paramerter = ob;
										msg = "<label style='margin-left:10px;color:green;'>当前资源已经配置了监控协议</label>";
										return false;
									}
							}else if(agreementId==5){
								//var dbType = $($($('#resRelTr').next().children('td')[1]).children('input')[0]).val();
								var dbType = $('#DBType').val();
								var dbName = $('#DBName').val();
								//var dbName = $($($('#resRelTr').next().next().children('td')[1]).children('input')[0]).val();
								if(ob.instType==dbType&&ob.instName==dbName){
									paramerter = ob;
									msg = "<label style='margin-left:10px;color:green;'>当前资源已经配置了监控协议</label>";
									return false;
								}else if(!dbType && dbName == ''){//sql查询中没有这两个字段，先判断一下
								 	if(ob.instType != null && ob.instType != '' && ob.instName != null && ob.instName != ''){
								 		paramerter = ob;
										msg = "<label style='margin-left:10px;color:green;'>当前资源已经配置了监控协议</label>";
										return false;
								 	}
							 	}
							}
					  }
						
					});
					
					
					var agreement = agreements[agreementId-1];
					if(agreement!=null){
						$('#agreement').html("<a href='#' onclick='openAddAgreement("+(paramerter==null?'':paramerter.id)+")' >"+agreement.text+"</a>"+msg+"");
					}
				},
				error:function(){
					getTopWin(window).getMessageBox().alert('服务器内部错误,请联系管理员','错误');
				}
			});
		}
		
		//打开采集协议配置页面
		function openAddAgreement(id) {
			var agreement = agreements[agreementId-1];
			var url ;
			var title= "";
			if(id!=null&&id!=''){
				url ="iframe:"+agreement.updateUrl+"?id="+id+"&isRef=false";
				title ='修改'+agreement.title;
			}else{
				url ="iframe:"+agreement.url+"?isRef=false&isResAdd=true&resType="+$('#resTypeName').val()+"&ip="+$('#ip').val();
				var unFixed = $($('#resRelTr').next().children('td')[1]).children('input')[0];
				var havingParent ='${res.name==null}';
				//没有父资源
				if(havingParent=='true'){
					unFixed = $($('#agreementTr').prev().children('td')[1]).children('input')[0];
				}
				//sql查询中没有这个字段，先判断一下
				if($(unFixed).val()){
					url +='&dbName='+$(unFixed).val();
				}
				title ='新增'+agreement.title;
			}
			
			var opt ;
			if(agreementId==1){ 
				opt ={ title: ""+title+"",width:530,height:420,buttons: {},closed:addAgreementClose};
			}else if(agreementId==2){
				opt= {title: ""+title+"",width:510,height:280,buttons: {},closed:addAgreementClose};
			}else if(agreementId==3||agreementId==5){
				opt ={title: ""+title+"",width:560,height:450,buttons: {},closed:addAgreementClose};
			}else if(agreementId==4){
				opt = {title: ""+title+"",width:510,height:360,buttons: {},closed:addAgreementClose};
			}
			getTopWin(window).openjBox(url,opt,""+agreement.windowId+"",window);
		}
		
		//关闭采集协议的回调事件
		function addAgreementClose(){
			if(agreementId==1||agreementId==2){
				isConfigireAgreement('ip',agreementId==1?'HOST':'WMI');
			}else if(agreementId==3||agreementId==5){
				isConfigireAgreement('ip','JDBC');
			}else if(agreementId==4){
				isConfigireAgreement('ip','JMX');
			}
		}
		
		function resetIt()
		{
			$(".tmptr").each(function(){
  					$(this).remove();
				});
			document.forms[0].reset();
			$.formValidator.resetTipState("1")
			
		}
		function setRoot(){
			var isChecked = $("#isRoot").attr("checked");
			if(isChecked){
				$("#resRelTr").hide();
				$("#resRelTr").blur();
				$("#presname").css("textDecoration","line-through");
			}else{
				$("#resRelTr").show();
				$("#presname").css("textDecoration","none");
			}
		}
		
		//返回
		function back(){
			var backUrl = document.referrer;
			location.assign(backUrl);
		}
		
		
		
	</script>

  </head>
  <body>
	<form  name="resForm" id="resForm" method="post">
	<input type="hidden" name="parentId" id="parentId" value="${res.id }" />
	<input type="hidden" name="viewId" id="viewId" value="${resView.id }" />
    <table class="table_eidt" id="restable">
		<tbody>
			<tr>
	    		<td class="td_left" style="width: 150px">父资源</td>
	    		<td class="td_right">
					<span id="presname">${res.name }</span> &nbsp;&nbsp;&nbsp;&nbsp;
					<input type='checkbox' value="1" name="isRoot" id="isRoot"  onclick="setRoot();"/>
					<label for="isRoot" tabindex="1">设为顶级资源</label>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td class="td_left">
					<span class="span_alert">*</span> 资源类型
				</td>
	    		<td class="td_right">
						<input type="text" name="resTypeName" id="resTypeName" class="input_text tree_res" onfocus="showMenu(); return false;"/>
						<span id="resTypeNameTip"></span>
						<input type="hidden" name="resTypeId" id="resTypeId"  />
				</td>
	    	</tr>
	    	<tr>
	    		<td class="td_left">
					<span class="span_alert">*</span> 资源IP
				</td>
	    		<td class="td_right">
						<input type="text" name="ip" id="ip"   class="input_text"  maxlength="15"/>
						<span id="ipTip"></span>
				</td>
	    	</tr>
	    	<tr>
	    		<td class="td_left">
					<span class="span_alert">*</span> 资源名称
				</td>
	    		<td class="td_right">
						<input type="text" name="name" id="name"   class="input_text"/>
						<span id="nameTip"></span>
				</td>
	    	</tr>
	    	<tr>
	    		<td class="td_left">
					<span class="span_alert">*</span> 采集器
				</td>
	    		<td class="td_right">
	    				<select id="probeId" name = "probeId"  class = "select" style="width:227px;" >
	    					 <option value="" title=''>---- 请选择采集器 ----</option>
	    					<%
	    						List<Probe> probes = (List<Probe>)request.getAttribute("probeList");
	    						if(probes!=null)
	    						for(Probe  p : probes){
	    						    if(p.getStatus()==3){
	  	    			    				out.println("<option value='"+p.getId()+"' title='/bsm/style/default/bsm/images/proberun.png' >"+p.getId()+"_"+p.getName()+"</option>");
	  	    						    }else{
	  	  	    			    			out.println("<option value='"+p.getId()+"' title='/bsm/style/default/bsm/images/probestop.png' >"+p.getId()+"_"+p.getName()+"</option>");
	  	    						    }
	    						}
	    					%>
	    				</select>
	    				<span id="probeIdTip"></span>
				</td>
	    	</tr>
	    	<c:if test="${res.name!=null}">
	    	<tr id="resRelTr">
	    		<td class="td_left">
					<span class="span_alert">*</span> 与父资源关系
				</td>
	    		<td class="td_right">
					<input type="text" name="resRelName" id="resRelName" readonly value="支撑" class="input_text" onfocus="showRelTree(); return false;"/>
					<input type="hidden" name="resRelId" id="resRelId" value="<%=RelationConstants.SUPPORT %>" />
				</td>
	    	</tr>
	    	</c:if>
	    	<tr id="agreementTr">
	    		<td class="td_left">
					<span class="span_alert">*</span> 监控协议
				</td>
	    		<td class="td_right">
	    				<span id="agreement"></span>
				</td>
	    	</tr>
	    	<tr id="DBTypeTr"  style="display: none">
	    		<td class="td_left">
					数据库类别
				</td>
	    		<td class="td_right">
						<input type="text" name="DBType" id="DBType" class="input_text"/>
				</td>
	    	</tr>
	    	<tr id="DBNameTr"  style="display: none">
	    		<td class="td_left">
					数据库名
				</td>
	    		<td class="td_right">
						<input type="text" name="DBName" id="DBName"   class="input_text"/>
				</td>
	    	</tr>
	    	<tr id="SQLTr"  style="display: none">
	    		<td class="td_left">
					查询sql语句
				</td>
	    		<td class="td_right">
					<textarea class="input_textarea" name="SQL" id="SQL"   rows="3"  ></textarea>
				</td>
	    	</tr>
	    	<tr id="shellTr"  style="display: none">
	    		<td class="td_left">
					SHELL脚本
				</td>
	    		<td class="td_right">
	    			<textarea class="input_textarea" name="shell" id="shell"  rows="3"  ></textarea>
				</td>
	    	</tr>
	    	<tr id="regexTr" style="display: none">
	    		<td class="td_left">
					匹配规则
				</td>
	    		<td class="td_right">
						<input type="text" name="regex" id="regex"   class="input_text" style="width:420px;"/>
				</td>
	    	</tr>
	    	<tr id="desc">
	    		<td class="td_left">
					 描述
				</td>
	    		<td class="td_right">
					<textarea class="input_textarea" name="desc" rows="3" onkeydown="this.value=this.value.substring(0,225)" ></textarea>
				</td>
	    	</tr>
	    	
	    	<tr>
    			<th class="td_left">
    				<label>指标定义</label>
    			</th>
    			<td class="td_right">
    				<div style="padding: 2px">
					 	<a href="javascript:addProperty();">新增</a>
					</div>
					<div style="width: 650px;">
						<table id="propertyTable" cellpadding="0" cellspacing="0" class="display dataTable">
							<thead>
								<tr class="changecolor">
									<th width="50" class="sorting_disabled" colspan="1" rowspan="1">操作</th>
									<th width="400" class="sorting_disabled" colspan="1" rowspan="1">指标名称</th>
									<th width="200" class="sorting_disabled" colspan="1" rowspan="1">数据类型</th>
								</tr>
							</thead>
						</table>
					</div>
    			</td>
    		</tr>
    		<tr>
    			<th class="td_left">
    				<label>事件类别定义</label>
    			</th>
    			<td class="td_right">
    				<div style="padding: 2px">
					 	<a href="javascript:addEventType();">新增</a>
					</div>
					<div style="width: 650px;">
						<table id="eventTypeTable" cellpadding="0" cellspacing="0" class="display dataTable">
							<thead>
								<tr class="changecolor">
									<th width="50" class="sorting_disabled" colspan="1" rowspan="1">操作</th>
									<th width="400" class="sorting_disabled" colspan="1" rowspan="1">类别名称</th>
									<th width="200" class="sorting_disabled" colspan="1" rowspan="1">事件性质</th>
								</tr>
							</thead>
						</table>
					</div>
    			</td>
    		</tr>
	    	
		</tbody>
    </table>
    	<div  class="btn-div" >
    			<button type="submit" id ="saveBt" value="保存" class="btn-4" >保存</button>
    			<button type="button" onclick="back()" class="btn-4" >返回</button>
    	</div>	
   </form>

   
    <div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	  <ul id="resTypeTree" class="ztree" style="margin-top:0;padding-left:0;  width:220px; height:350px; "></ul>
   </div>
     <div id="relContent" class="menuContent" style="display:none; position: absolute;">
	  <ul id="relRelTree" class="ztree" style="margin-top:0;padding-left:0;  width:220px; height:120px; "></ul>
   </div>
  </body>
</html>
